const axios = require('axios');

async function checkImages() {
  try {
    // 登录获取token
    const loginResponse = await axios.post('http://localhost:3001/api/auth/login', {
      email: 'admin@example.com',
      password: '123456'
    });
    
    const token = loginResponse.data.data.token;
    console.log('登录成功，token:', token ? '已获取' : '未获取');
    
    if (!token) {
      console.log('登录失败，完整响应:', loginResponse.data);
      return;
    }
    
    // 获取菜品数据
    const itemsResponse = await axios.get('http://localhost:3001/api/menu/items', {
      headers: {
        'Authorization': `Bearer ${token}`
      }
    });
    
    console.log('菜品API响应结构:', {
      success: itemsResponse.data.success,
      hasData: !!itemsResponse.data.data,
      hasItems: !!itemsResponse.data.data?.items,
      itemsLength: itemsResponse.data.data?.items?.length
    });
    
    const items = itemsResponse.data.data?.items || [];
    console.log(`\n获取到 ${Array.isArray(items) ? items.length : '非数组'} 个菜品`);
    
    if (!Array.isArray(items)) {
      console.log('菜品数据不是数组格式');
      return;
    }
    
    // 检查前5个菜品的图片URL
    console.log('\n前5个菜品的图片信息:');
    items.slice(0, 5).forEach((item, index) => {
      console.log(`${index + 1}. ${item.name}`);
      console.log(`   ID: ${item.id}`);
      console.log(`   图片URL: ${item.image_url || '无'}`);
      console.log(`   分类ID: ${item.category_id}`);
      console.log('---');
    });
    
    // 统计图片URL情况
    const withImages = items.filter(item => item.image_url);
    const withoutImages = items.filter(item => !item.image_url);
    
    console.log(`\n图片统计:`);
    console.log(`- 有图片: ${withImages.length} 个`);
    console.log(`- 无图片: ${withoutImages.length} 个`);
    
    if (withImages.length > 0) {
      console.log('\n图片URL格式示例:');
      withImages.slice(0, 3).forEach(item => {
        console.log(`- ${item.name}: ${item.image_url}`);
      });
    }
    
  } catch (error) {
    console.error('检查图片时发生错误:', error.message);
    if (error.response) {
      console.error('响应状态:', error.response.status);
      console.error('响应数据:', error.response.data);
    }
  }
}

checkImages();